package club.jdiy.core.base.domain;

import club.jdiy.core.base.JpaFilter;
import club.jdiy.core.base.WhereBuilder;

/**
 * 指示当前实体支持JPA动态查询
 *
 * @author ziquee(子秋) QQ号:39886616 主页: http://www.jdiy.club
 * @version 20210309
 */
public interface JpaFilterable extends Filterable{

    /**
     * 通过使用入参builder.append(String condition)方法动态加添JPQL查询条件(condition)字符串片段.  条件片段中可使用变量o表示当前Entity对象 <br/>
     * 示例1 (常规jpql动态条件)：<pre>
     *  public JpaFilter(WhereBuilder builder){
     *      builder.append("o.disableFlag=false");
     *      if(state != null) builder.append(" and o.state=?1", state);
     *      if(StringUtils.hasText(key_)) builder.append(" and (o.name like ?1 or o.remark like ?1)", "%" + key_.trim() + "%");
     *      if(user.id != '') builder.append(" and o.user.id=?1 and o.user.removed=?2",  user.id, false);
     *      if(foo_ != null) builder +=" and exists (select 0 from OtherEntity e where e.eid=o.id and e.foo=?1", foo_);
     *      //...  更多条件略
     *      return new JpaFilter(this.class, builder, "o.dtAdd desc, o.sortIndex asc");
     *  }
     * </pre><br/>
     * * 示例2 (使用 join查询)：<pre>
     *  public JpaFilter(WhereBuilder builder){
     *      StringBulider joins=new StringBuilder("");
     *      //... 其它常规条件略
     *      if(orderItemState_ != null){
     *          joins.append(" join o.orderItemList oi");
     *          builder.append(" and oi.state=?1", state);
     *      }
     *      //...  更多条件略
     *      return new JpaFilter(this.class, builder, "o.dtAdd desc, o.sortIndex asc", joins.toString());
     *  }
     * </pre><br/>
     *
     * @return 动态生成的JpaFilter查询条件对象
     */
    JpaFilter createFilter(WhereBuilder builder);
}
